package nam.bt.zajnbovv.jewels_new_pro;

import nam.bt.zajnbovv.jewels_new_pro.config.MyConfig;
import nam.bt.zajnbovv.jewels_new_pro.util.Util;
import nam.bt.zajnbovv.jewels_new_pro.util.UtilActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
 
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
 
public class MyApp extends Activity{
    AdView adView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UtilActivity.requestWindowFeature(this);
    }
 
    //-------------------------------------------------
    /**
    * Load thêm phần quảng cáo
    */
    public void addAdmob(){
        try{
            LinearLayout admob = (LinearLayout)findViewById(R.id.admob);     
            if(admob != null){
                adView = new AdView(this, AdSize.BANNER, MyConfig.keyAdmob);
                admob.addView(adView);
                adView.loadAd(new AdRequest());
            }
        }catch(Exception e){}
    }
    //-------------------------------------------------
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        try{
            if(adView != null)
                adView.destroy();
        }catch(Exception e){}
    }
    //-------------------------------------------------
    public void showDialogDownloadGamePiakchu(){     
        if(!Util.appInstalledOrNot("gioi.developer.pikachu_pro", this)){     
            AlertDialog.Builder md = new AlertDialog.Builder(this);
            md.setTitle("Tải game miễn phí");
            md.setMessage("Tải game Pikachu PRO miễn phí");
            md.setNegativeButton("Đồng ý", new DialogInterface.OnClickListener() {         
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    try {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=gioi.developer.pikachu_pro"));
                        startActivity(marketIntent);
                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }
            });
            md.setPositiveButton("Đóng", new DialogInterface.OnClickListener() {
             
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    MyApp.this.finish();
                }
            });
            md.show();
        }
        else MyApp.this.finish();
    }
 
    //-------------------------------------------------
//    public void addAdBanner(){
//        try{
//            ImageView imageView_adBanner = (ImageView)findViewById(R.id.imageView_adBanner);
//            AdBanner mAdBanner = new AdBanner(this, imageView_adBanner);
//        }catch(Exception e){
//         
//        }
//    }
}
